package implementation;

public class RockPaperScissors {
	Result result = Result.LOST;
	
	public RockPaperScissors(){
		
	}
	
	public Result play(RPSEnum p1, RPSEnum p2){
		
		
		if((p1 == RPSEnum.ROCK && p2 == RPSEnum.SCISSORS) ||
		(p1 ==  RPSEnum.SCISSORS && p2 ==  RPSEnum.PAPER) ||
		(p1 ==  RPSEnum.PAPER && p2 ==  RPSEnum.ROCK)){
			return result = Result.WIN;
		}else if(p1 == p2){
			return result = Result.TIE;
		}else{
			return result;
		}
		
	}
	public Result play(Player p1, Player p2){
		//Scoring
		for(int i = 0; i < Player.getNbMoves(); i++){
			switch(play(p1.getNextMove(), p2.getNextMove())){
			case WIN:
				p1.setScore(p1.getScore()+1);
				break;
			case LOST:
					p2.setScore(p2.getScore()+1);
			case TIE:
				p1.setScore(p1.getScore()+1);
				p2.setScore(p2.getScore()+1);
				default:  
					p1.setScore(p1.getScore()+1);
					p2.setScore(p2.getScore()+1);
					break;					
			}
		}
		
		if(p1.getScore() > p2.getScore()) return Result.WIN;
		else if(p1.getScore() < p2.getScore()) return Result.LOST;
		else return Result.TIE;
	}
}
